package cn.com.wdjedu.androidapp.wjeduandroid.support.lib.mvputils;

import rx.Subscription;

/**
 * 基础的Presenter层
 */
public abstract class BasePresenter<T extends BaseView> {
    public T mView;
    public Subscription subscription;

    public void attach(T mView) {
        this.mView = mView;
    }


    public void dettach() {
        mView = null;
    }

    //错误时的操作
    public void showError(String error) {
        if (mView != null) {
            mView.hideLoading();
            mView.showError(error);
        }
    }

    /**
     * 關閉资源防止泄露
     */
    public void  close(){
        if (subscription!=null&&!subscription.isUnsubscribed()){
            subscription.unsubscribe();
        }
    }
}